package Hash_and_ordered_tables;

import java.util.TreeMap;

public class ordered_list {
    public static void main(String[] args) {
        TreeMap<Integer, String> treeMap1 = new TreeMap<>();

        treeMap1.put(3, "我是3");
        treeMap1.put(0, "我是3");
        treeMap1.put(7, "我是3");
        treeMap1.put(2, "我是3");
        treeMap1.put(5, "我是3");
        treeMap1.put(9, "我是3");

        System.out.println(treeMap1.containsKey(7));
        System.out.println(treeMap1.containsKey(6));
        System.out.println(treeMap1.get(3));

        treeMap1.put(3, "他是3");
        System.out.println(treeMap1.get(3));

        treeMap1.remove(3);
        System.out.println(treeMap1.get(3));

        System.out.println(treeMap1.firstKey());
        System.out.println(treeMap1.lastKey());
        // <=5 离5最近的key告诉我
        System.out.println(treeMap1.floorKey(5));
        // <=6 离6最近的key告诉我
        System.out.println(treeMap1.floorKey(6));
        // >=5 离5最近的key告诉我
        System.out.println(treeMap1.ceilingKey(5));
        // >=6 离6最近的key告诉我
        System.out.println(treeMap1.ceilingKey(6));

//      Node 是一个自定义类型,类似于c语言的结构体
//		Node node3 = new Node(3);
//		Node node4 = new Node(4);
//		TreeMap<Node, String> treeMap2 = new TreeMap<>();
//		treeMap2.put(node3, "我是node3");
//		treeMap2.put(node4, "我是node4");
        //这样写会出错,因为在有序表中要可以比较
    }
}
